package com.example.reward.fragments;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.reward.MainActivity;
import com.example.reward.R;

public class HomeFragment extends Fragment {

    public HomeFragment() {
        super(R.layout.fragment_home);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        Button btnGoToCalc = view.findViewById(R.id.btnGoToCalc);
        btnGoToCalc.setOnClickListener(v -> {
            // 获取宿主 Activity，并调用它的 switchFragment 方法
            if (getActivity() instanceof MainActivity) {
                ((MainActivity) getActivity()).switchFragment(1);  // 跳转到 CalculatorFragment
                ((MainActivity) getActivity()).switchFragmentAndUpdateTab(1);  // 跳转到 CalculatorFragment
            }
        });
    }
}
